package com.ruoyi.demooo1.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.demooo1.domain.TedAdvise;
import com.ruoyi.demooo1.mapper.TedAdviseMapper;
import com.ruoyi.demooo1.service.ITedAdviseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * TedAdviseService业务层处理
 *
 * @author ruoyi
 * @date 2023-08-18
 */
@Service
public class TedAdviseServiceImpl implements ITedAdviseService
{
    @Autowired
    private TedAdviseMapper tedAdviseMapper;

    /**
     * 查询TedAdvise
     *
     * @param ID TedAdvise主键
     * @return TedAdvise
     */
    @Override
    public TedAdvise selectTedAdviseByID(String ID)
    {
        return tedAdviseMapper.selectTedAdviseByID(ID);
    }

    /**
     * 查询TedAdvise列表
     *
     * @param tedAdvise TedAdvise
     * @return TedAdvise
     */
    @Override
    public List<TedAdvise> selectTedAdviseList(TedAdvise tedAdvise)
    {
        String username = SecurityUtils.getUsername();
        if("admin".equals(username) || "sysadmin".equals(username)){
            tedAdvise.setCreateBy("");
        }else {
            tedAdvise.setCreateBy(SecurityUtils.getUserId().toString());
        }
        return tedAdviseMapper.selectTedAdviseList(tedAdvise);
    }

    /**
     * 新增TedAdvise
     *
     * @param tedAdvise TedAdvise
     * @return 结果
     */
    @Override
    public int insertTedAdvise(TedAdvise tedAdvise)
    {
        tedAdvise.setCreateTime(DateUtils.getNowDate());
        tedAdvise.setUpdateTime(DateUtils.getNowDate());
        tedAdvise.setCreateBy(SecurityUtils.getUserId().toString());
        tedAdvise.setUpdateBy(SecurityUtils.getUserId().toString());
        tedAdvise.setId(UUID.randomUUID().toString().replace("-",""));
        return tedAdviseMapper.insertTedAdvise(tedAdvise);
    }

    /**
     * 修改TedAdvise
     *
     * @param tedAdvise TedAdvise
     * @return 结果
     */
    @Override
    public int updateTedAdvise(TedAdvise tedAdvise)
    {
        tedAdvise.setUpdateTime(DateUtils.getNowDate());
        return tedAdviseMapper.updateTedAdvise(tedAdvise);
    }

    /**
     * 批量删除TedAdvise
     *
     * @param IDs 需要删除的TedAdvise主键
     * @return 结果
     */
    @Override
    public int deleteTedAdviseByIDs(String[] IDs)
    {
        return tedAdviseMapper.deleteTedAdviseByIDs(IDs);
    }

    /**
     * 删除TedAdvise信息
     *
     * @param ID TedAdvise主键
     * @return 结果
     */
    @Override
    public int deleteTedAdviseByID(String ID)
    {
        return tedAdviseMapper.deleteTedAdviseByID(ID);
    }

    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String result = encoder.encode("123456");
        System.out.println(result);
        boolean matches = encoder.matches("123", result);
        System.out.println(matches);
    }
}
